#include <string>
#include <fstream>
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include "def.h"

using namespace std;

#include "Mutex.h"
#include "Cond.h"
#include "BiContainer.h"
#include "Lockable.h"
#include "VarCol.h"
#include "Formattable.h"
#include "TableState.h"
#include "Table.h"

TableState::TableState (Table& tbl) {
 table = &tbl;
 page = 0;

 createVarColStreams();
}

void TableState::createVarColStreams () {
 vcs = new fstream [ table->varCols.size() ];

 int i = 0;
 map<int, VarCol>::iterator itr = table->varCols.begin ();
 map<int, VarCol>::iterator itrEnd = table->varCols.end ();
 
 while (itr != itrEnd) { /* Create an fstream for each VarCol */
  itr->second.open (vcs [i]);
  varColStreams.insert ( pair<int, fstream*> (itr->first, vcs + i) );
  i++;
  itr++;
 }
}

TableState::~TableState () {
 delete [] vcs;
}
